<?php
/*
 * filename: cls.php
 * author: xuguoyu
 * date: 2010/4/22
 * update:
 * description: 
 */

class Operate
{
	var $DB;

	function Operate(){ //建立数据库连接
		$this->DB = conn();
	}

	// 添加新买商品
	function add_item( $arr ){
		$sql = "insert into item (`caption`, `price`, `amount`, `time`, `appraise`, `area`, `shop_name`, `type`, `explain`, `user`) values('{$arr['caption']}', {$arr['price']}, {$arr['amount']}, '{$arr['time']}', '{$arr['appraise']}', '{$arr['area']}', '{$arr['shop_name']}', {$arr['type']}, '{$arr['explain']}', {$arr['uid']})";
		if($this->DB->query($sql)){ //添加成功
			return true;
		}else{
			return false;
		}
	}

	// 修改商品信息
	function edit_item( $arr ){
		$sql = "update item set `caption`='{$arr['caption']}', `price`={$arr['price']}, `amount`={$arr['amount']}, `time`='{$arr['time']}', `appraise`='{$arr['appraise']}', `area`='{$arr['area']}', `shop_name`='{$arr['shop_name']}', `type`={$arr['type']}, `explain`='{$arr['explain']}' where id={$arr['id']}";
		if($this->DB->query($sql)){ //修改成功
			return true;
		}else{
			return false;
		}
	}

	// 删除商品信息
	function delete_item( $id ){
		$sql = "delete from item where id={$id}";
		if($this->DB->query($sql)){ //删除成功
			return true;
		}else{
			return false;
		}
	}
}
?>